#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created by bolin on 2017/8/13.
"""

import logging

from smAdmin.models import SmerpAccount, SmerpErpinfo, SmerpProduct, SmerpMaterial, SmerpProductMaterial

logger = logging.getLogger("django")


def getAccount():
	try:
		# 查询id为1的企业信息
		erpinfo = SmerpErpinfo.objects.get(id=1)

		# 输出信息
		print  erpinfo, erpinfo.smerpaccount, erpinfo.full_name

		# 查询id为1的账号信息
		account = SmerpAccount.objects.get(id=1)
		print account, account.email
		# 由于smerperpinfo外键关联了SmerpAccount的related_name为smerperpinfo，下面这样可以直接这样使用，显示账号对应的企业信息
		print account.smerperpinfo # 需要确认有id为1关联的企业信息

		# 打印账号所有的品牌信息
		for brand in account.smerpbrands.all():
			print brand, brand.name_zh

		# 查询产品
		product = SmerpProduct.objects.get(id=1)

		# 打印产品所有的管理的材料信息
		for material in product.smerpmaterials.all():
			print product.name, material, material.name

	except:
		logger.exception("", exc_info=True)
